package com.swm.util;

import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;

/**
 * @author 师文明
 * @data 2024/12/13 下午3:28
 **/
public class jsutil {
    public static void main(String[] args) {
        // 创建一个ScriptEngineManager实例
        ScriptEngineManager manager = new ScriptEngineManager();
        // 获取JavaScript引擎
        ScriptEngine engine = manager.getEngineByName("nashorn");

        try {
            // 执行JavaScript代码
            engine.eval("print('Hello, JavaScript from within Java!');");
        } catch (ScriptException e) {
            e.printStackTrace();
        }
    }
}
